from sqlalchemy import Column, String, DateTime, Float, func, event
from sqlalchemy.dialects.mysql import INTEGER
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()


class TbDvpunitbaisc(Base):
    __tablename__ = 'tb_dev_unit_info'
    __table_args__ = {'comment': '开发单元基本信息表'}

    DvpUnit_ID = Column(INTEGER, primary_key=True, nullable=False, comment='开发单元ID')
    DvpUnit_Name = Column(String(30), unique=True, nullable=False, comment='开发单元')
    Belong_DvpUnit_Name = Column(String(30), comment='隶属开发单元名称')
    DvpUnit_Rank = Column(String(30), comment='开发单元级别')
    Remark = Column(String(200), comment='备注')


class TbReservoirunitbaisc(Base):
    __tablename__ = 'tb_reservoir_unit_info'
    __table_args__ = {'comment': '储层单元基本信息表'}

    Reservoir_ID = Column(INTEGER, primary_key=True, nullable=False, comment='储层ID')
    Reservoir_Name = Column(String(30), unique=True, nullable=False, comment='储层名称')
    Layer_Name = Column(String(30), comment='层为名称')
    Belong_Dev_unit = Column(String(30), comment='隶属开发单元')
    Reservoir_Type = Column(String(30), comment='储层类型')
    Fluid_Type = Column(String(30), comment='流体类型')
    Rock_Type = Column(String(30), comment='岩性类型')
    Space_Type = Column(String(30), comment='空间类型类型')
    Permeate_Type = Column(String(30), comment='渗透类型')
    Pressure_Type = Column(String(30), comment='压力类型')
    Temperature_Type = Column(String(30), comment='温度类型')
    Remark = Column(String(200), comment='备注')


class TbWellbasic(Base):
    __tablename__ = 'tb_well_basic'
    __table_args__ = {'comment': '油井基本信息表'}

    Well_ID = Column(INTEGER(30), primary_key=True, nullable=False, comment='井号ID')
    Well_Name = Column(String(30), unique=True, nullable=False, comment='井号')
    GeoCoordX = Column(Float(30), comment='大地坐标X')
    GeoCoordY = Column(Float(30), comment='大地坐标Y')
    Belong_Unit_Name = Column(String(30), nullable=False, comment='隶属单元名称')
    Remark = Column(String(200), comment='备注')


class TbRockCore(Base):
    __tablename__ = 'tb_rock_core'
    __table_args__ = {'comment': '岩芯基本信息表'}

    Core_ID = Column(INTEGER(30), primary_key=True, nullable=False, comment='岩芯ID')
    Core_Name = Column(String(30), nullable=False, comment='岩芯名')
    Belong_Well_Name = Column(String(30), comment='隶属井名称')
    Fetch_Time = Column(DateTime, comment='创建时间', default=func.now())
    Remark = Column(String(200), comment='备注')


class TbCoreParam(Base):
    __tablename__ = 'tb_rock_core_param'
    __table_args__ = {'comment': '岩芯参数(岩芯全部参数)'}
    Parameter_ID = Column(INTEGER, primary_key=True, comment='参数ID')
    Parameter_Ecode = Column(String(50), unique=True, nullable=False, comment='参数编码')
    Parameter_Name = Column(String(50), unique=True, nullable=False, comment='参数名称')
    Sensitivity_Type = Column(INTEGER, comment='输出敏感性类型')
    Parameter_UOM_Name = Column(String(50), comment='参数计量单位')


class TbCoreData(Base):
    __tablename__ = 'tb_rock_core_data'
    __table_args__ = {'comment': '模型训练参数数据表(岩芯全部参数的值)'}
    Core_ID = Column(INTEGER, autoincrement=True, primary_key=True, comment='岩芯ID')
    Parameter_ID = Column(INTEGER, primary_key=True, comment='参数ID')
    Parameter_Value = Column(Float(30, True), comment='参数值')

